import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_syt/datas/user_info.dart';
import 'package:flutter_syt/domain/widgets/list_item.dart';
import 'package:flutter_syt/generated/l10n.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/theme/font_styles.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

@RoutePage(name: "manageAccount")
class ManageAccountPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ManageAccountState();
  }
}

class _ManageAccountState extends State<ManageAccountPage> {
  @override
  Widget build(BuildContext context) {
    List<ListItemEntity> listData = [
      UserInfo.me.registerType == '2'
          ? ListItemEntity(
              S.of(context).login_email,
              null,
              UserInfo.me.email ?? '',
              () => {},
              isShowRightIcon: false,
            )
          : ListItemEntity(
              S.of(context).mobile_number,
              null,
              UserInfo.me.phone_number,
              () => {},
              isShowRightIcon: false,
            ),
      ListItemEntity(
        S.of(context).password,
        null,
        S.of(context).change_password,
        () => {
          RouteManager.push(
            context,
            RoutMapping.resetPasswordPage(),
          )
        },
        isShowBorder: false,
      ),
    ];

    return Scaffold(
      appBar: AppBar(
        title: Text(
          S.of(context).account_management,
        ),
      ),
      body: Column(
        children: [
          Container(
            margin: EdgeInsets.all(10.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              color: ThemeColor.bkColorFFFFFF,
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.min,
              children: listData
                  .map((e) => GestureDetector(
                        onTap: ClickUtils.debounce(() => e.onTap),
                        child: Container(
                          // color: Colors.blueGrey,
                          alignment: Alignment.center,
                          child: ListItem(e),
                        ),
                      ))
                  .toList(),
            ),
          ),
          Spacer(),
          SafeArea(
            child: Container(
              margin: EdgeInsets.all(30),
              child: ElevatedButton(
                  child: Text(
                    S.of(context).delete_account,
                    style: TextStyle(fontWeight: FontWeight.bold),
                  ),
                  onPressed: ClickUtils.debounce(
                    () {
                      RouteManager.push(
                        context,
                        RoutMapping.removeAccountNotice(),
                      );
                    },
                  )),
            ),
          ),
        ],
      ),
    );
  }
}
